const http = require('http');
const server = http.createServer((req, res) => {
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    if (req.method === 'POST') {
        let body = '';
        req.on('data', (chunk) => {
            body += chunk.toString();
        });
        req.on('end', () => {
            // try {
            // postData = JSON.parse(body);
            // } catch (e) {
            // postData = querystring.parse(body);
            // }
            console.log('POST请求所提交的数据：', body);
            res.writeHead(200, {
                'Content-Type': 'application/json'
            });
            res.end(JSON.stringify({
                method: 'POST',
                data: postData
            }));
        });
    } else {
        res.end('success!!!');
    }
});
const port = 9999;
server.listen(port, () => {
    console.log("服务器运行的地址是： http: //localhost:${port}/");
});